<?php
/**
 * @file name : module_group_model.php
 * @package   :
 * @author    : Vo Thanh Minh
 * @email     : <thanhminhld@yahoo.com - thanhminhld@gmail.com>
 * @copyright : 2011
 *
 */
 if (!defined('BASEPATH')) {
    exit('No direct script access');
}

class Module_group_model extends Base_Model
{
    /**
     * @function __construct
     * @author   Vo Thanh Minh <thanhminhld@yahoo.com - thanhminhld@gmail.com>
     */
	public function __construct()
	{
		parent::__construct();
		$this->_tbl       = 'module_group';
	}
	/**
	 * getTotalRows
	 *
	 * @author Vo Thanh Minh <thanhminhld@yahoo.com - thanhminhld@gmail.com>
	 * @access public
	 * @param array $arrWhere
	 *
	 * @return int
	 */
    public function getTotalRows($arrWhere = array(), $field_groupby = '')
    {
	    if (count($arrWhere) > 0) {
            $this->db->where($arrWhere);
        }
        if (!empty($field_groupby) && is_string($field_groupby)) {
            if ($this->db->field_exists($field_groupby, $this->_tbl)) {
                $this->db->group_by($field_groupby);
            }
        }

		$query = $this->db->get_where($this->_tbl, $arrWhere);

		return $query->num_rows();
    }
	/**
	 * @function loadList
	 *
	 * @author Vo Thanh Minh <thanhminhld@yahoo.com - thanhminhld@gmail.com>
	 * @access public
	 * @return array
	 */
	public function loadList($arrWhere = array(), $limit = 10, $offset = 0)
	{
	    $this->db->order_by('g_ordering', 'asc');
        if ($limit == 'all') {
            $query = $this->db->get_where($this->_tbl, $arrWhere);
        } else {
            $query = $this->db->get_where($this->_tbl, $arrWhere, $limit, $offset);
        }
        $arrList = array();
        if ($query->num_rows() > 0) {
            foreach($query->result() as $row) {
                $arrList[] = $row;
            }
        }
		return $arrList;
	}
    /**
     * @function loadRecord
     *
     * @author Vo Thanh Minh <thanhminhld@yahoo.com - thanhminhld@gmail.com>
     * @access public
     * @param  int $m_id
     * @return object
     */
    public function loadRecord($m_id)
    {
        $where = array('id'  => $m_id);

        $itemObj = $this->db->get_where($this->_tbl, $where);
        $arrList = array();
        if ($itemObj->num_rows() > 0) {
            foreach($itemObj->result() as $row) {
               $arrList = $row;
            }
        }
        return $arrList;
    }
}